package cn.steel.config;

import cn.steel.base.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ResponseData<?> handleRuntimeException(RuntimeException ex) {
        log.error("运行时异常", ex);
        return ResponseData.fail("操作失败: " + ex.getMessage());
    }

    @ExceptionHandler(IllegalArgumentException.class)
    @ResponseBody
    public ResponseData<?> handleIllegalArgumentException(IllegalArgumentException ex) {
        log.warn("参数异常", ex);
        return ResponseData.fail("请求参数错误: " + ex.getMessage());
    }
}
